package com.wmyg.antifake.utils;

import com.wmyg.antifake.codecreator.DozenCreator;
import com.wmyg.antifake.entity.Record;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-05-08
 */
public class MiaomarkDozenCreator implements DozenCreator<Record, MiaomarkDozen> {

    private final static Integer MAX_COUNT_OF_DOZEN = 50000;

    private final static String CASE_SYMBOL = "X";

    private final static String BOX_SYMBOL = "H";

    private final static String PACK_SYMBOL = "D";

    @Override
    public Collection<MiaomarkDozen> create(Record foundation) {
        List<MiaomarkDozen> dozens = new ArrayList<>();
        Integer enterCase = foundation.getEnterCase();
        Integer enterBox = foundation.getEnterBox();
        Integer enterPack = foundation.getEnterPack();
        Integer totalBox = foundation.getTotalBox();
        Integer totalPack = foundation.getTotalPack();
        if (foundation.getEnterCase() > 0) {
            Integer caseBatchId = 0;
            while (enterCase > 0) {
                MiaomarkDozen dozen = new MiaomarkDozen();
                dozen.setPackLevel(CASE_SYMBOL);
                dozen.setDozenId(caseBatchId);
                dozen.setPartOneStart(0);
                dozen.setPartOneNum(1);
                dozen.setPartTwoStart(caseBatchId * MAX_COUNT_OF_DOZEN);
                dozen.setPartTwoNum(enterCase > MAX_COUNT_OF_DOZEN ? MAX_COUNT_OF_DOZEN : enterCase);
                dozen.setPartThrStart(foundation.getEnterBox());
                dozen.setPartThrNum(1);
                dozens.add(dozen);
                enterCase = enterCase - MAX_COUNT_OF_DOZEN;
                caseBatchId ++;
            }
            if (foundation.getEnterBox() > 0) {
                Integer boxBatchId = 0;
                if (foundation.getEnterBox() > MAX_COUNT_OF_DOZEN) {
                    Integer dozensEachCase = foundation.getEnterBox() / MAX_COUNT_OF_DOZEN + 1; //6000 m5000 2
                    for (int i = 0; i < foundation.getEnterCase() ; i++) {
                        while (enterBox > 0) {
                            MiaomarkDozen dozen = new MiaomarkDozen();
                            dozen.setPackLevel(BOX_SYMBOL);
                            dozen.setDozenId(boxBatchId);
                            dozen.setPartOneStart(i);
                            dozen.setPartOneNum(1);
                            dozen.setPartTwoStart((boxBatchId - i * dozensEachCase) * MAX_COUNT_OF_DOZEN);
                            dozen.setPartTwoNum(enterBox > MAX_COUNT_OF_DOZEN ? MAX_COUNT_OF_DOZEN : enterBox);
                            dozen.setPartThrStart(foundation.getEnterPack());
                            dozen.setPartThrNum(1);
                            dozens.add(dozen);
                            enterBox = enterBox - MAX_COUNT_OF_DOZEN;
                            boxBatchId ++;
                        }
                        enterBox = foundation.getEnterBox();
                    }
                } else {

                }
            }
        }
        return dozens;
    }

}
